﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using litsdk;

namespace litqrcode
{
    internal partial class QrCodeUI : litsdk.ILitUI
    {
        public QrCodeUI()
        {
            InitializeComponent();
            this.ivContent.ShowVarName(true, false, true, this.tbContent);
            this.svSaveVarName.ShowVarName(true, false, false);
            this.SaveActivity = new Action(() =>
              {
                  qa.IsCreate = this.rbCreateQrCode.Checked;
                  qa.Content = this.tbContent.Text.Trim();
                  qa.SaveVarName = this.svSaveVarName.VarName;
                  qa.ImgSize = (int)this.nudImgSize.Value;
                  qa.ErrorCorrectionLevel = this.cbHint.SelectedIndex;
                  qa.Name = this.tbActivityName.Text.Trim();
              });
        }

        litqrcode.QrCodeActivity qa = null;
        public override string ActivityType => "litqrcode.QrCodeActivity";
        public override void SetActivity(Activity activity)
        {
            qa = activity as QrCodeActivity;
            this.rbCreateQrCode.Checked = qa.IsCreate;
            this.rbRecognizeQrCode.Checked = !qa.IsCreate;
            this.tbContent.Text = qa.Content;
            this.svSaveVarName.VarName = qa.SaveVarName;
            this.nudImgSize.Value = qa.ImgSize;
            this.cbHint.SelectedIndex = qa.ErrorCorrectionLevel;
            this.tbActivityName.Text = qa.Name;
        }

        private void rbCreateQrCode_CheckedChanged(object sender, EventArgs e)
        {
            if (rbCreateQrCode.Checked)
            {
                this.lbCreate.Text = "生成内容";
                this.lbSave.Text = "保存地址";
                this.lbImg.Visible = this.lbpx.Visible = this.nudImgSize.Visible = this.lbHint.Visible = this.cbHint.Visible = true;
            }
        }

        private void rbRecognizeQrCode_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rbRecognizeQrCode.Checked)
            {
                this.lbCreate.Text = "图片路径";
                this.lbSave.Text = "识别结果";
                this.lbImg.Visible = this.lbpx.Visible = this.nudImgSize.Visible = this.lbHint.Visible = this.cbHint.Visible = false;
            }
        }
    }
}
